import React, { Component } from 'react';
// React 事件传参
// 2. 通过 bind 函数进行传参 
class App extends Component {

  state = {
    list:[
      {
        id:1,
        text:"🍎"
      },
      {
        id:2,
        text:"🍌"
      }
    ]
  }
  handleDel = (index,...rest) => {
    console.log(index,rest);
    // let index = e.target.dataset.index;
    // console.log(index);
    let list = this.state.list;
    list.splice(index,1);
    this.setState({
      list
    })
  }
  render() {
    return (
      <div>
        <ul>
          {
            this.state.list.map((v,index)=>(
              <li key={v.id} >{v.text}<button onClick={this.handleDel.bind(this,index)}>删除</button></li>
            ))
          }
        </ul>
      </div>
    );
  }
}

export default App;
